package oficina;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import beans.ProveedorBean;
import beans.RodamientoBean;
import beans.StockBean;

import client.controlador.Controlador;
import client.view.Exito;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class IngresarProducto extends javax.swing.JFrame {
	private JLabel lblCodigo;
	private JTextField txtCodigo;
	private JTextField txtNombre;
	private JButton jButtonAceptar;
	private JLabel lblStockMin;
	private JTextField txtStockMinimo;
	private JTextField txtPrecio;
	private JButton jButtonCancelar;
	private JLabel lblPrecio;
	private JTextField txtMarca;
	private JLabel lblMarca;
	private JTextField txtOrigen;
	private JLabel lblOrigen;
	private JLabel lblNombre;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				IngresarProducto inst = new IngresarProducto();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public IngresarProducto() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				lblCodigo = new JLabel();
				getContentPane().add(lblCodigo);
				lblCodigo.setText("CODIGO");
				lblCodigo.setBounds(12, 12, 78, 16);
			}
			{
				txtCodigo = new JTextField();
				getContentPane().add(txtCodigo);
				txtCodigo.setBounds(79, 12, 104, 23);
			}
			{
				lblNombre = new JLabel();
				getContentPane().add(lblNombre);
				lblNombre.setText("NOMBRE");
				lblNombre.setBounds(12, 49, 75, 16);
			}
			{
				txtNombre = new JTextField();
				getContentPane().add(txtNombre);
				txtNombre.setBounds(79, 46, 232, 23);
			}
			{
				lblOrigen = new JLabel();
				getContentPane().add(lblOrigen);
				lblOrigen.setText("ORIGEN");
				lblOrigen.setBounds(12, 84, 74, 16);
			}
			{
				txtOrigen = new JTextField();
				getContentPane().add(txtOrigen);
				txtOrigen.setBounds(79, 81, 230, 23);
			}
			{
				lblMarca = new JLabel();
				getContentPane().add(lblMarca);
				lblMarca.setText("MARCA");
				lblMarca.setBounds(12, 119, 67, 16);
			}
			{
				txtMarca = new JTextField();
				getContentPane().add(txtMarca);
				txtMarca.setBounds(79, 116, 231, 23);
			}
			{
				lblPrecio = new JLabel();
				getContentPane().add(lblPrecio);
				lblPrecio.setText("PRECIO");
				lblPrecio.setBounds(12, 156, 55, 16);
			}
			{
				txtPrecio = new JTextField();
				getContentPane().add(txtPrecio);
				txtPrecio.setBounds(79, 153, 83, 23);
			}
			{
				txtStockMinimo = new JTextField();
				getContentPane().add(txtStockMinimo);
				txtStockMinimo.setBounds(281, 153, 82, 23);
			}
			{
				lblStockMin = new JLabel();
				getContentPane().add(lblStockMin);
				lblStockMin.setText("STOCK MINIMO");
				lblStockMin.setBounds(189, 156, 104, 16);
			}
			{
				jButtonAceptar = new JButton();
				getContentPane().add(jButtonAceptar);
				jButtonAceptar.setText("ACEPTAR");
				jButtonAceptar.setBounds(67, 208, 98, 34);
				jButtonAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						try{
							String pre=txtPrecio.getText().replace(",", ".");
							if(!txtCodigo.getText().isEmpty()&&!txtNombre.getText().isEmpty()&&!txtMarca.getText().isEmpty()&&!txtOrigen.getText().isEmpty()&&!pre.isEmpty()&&!txtStockMinimo.getText().isEmpty()){
								int stockMin=Integer.valueOf(txtStockMinimo.getText());
								int codigo=Integer.valueOf(txtCodigo.getText());
								double precio=Double.valueOf(pre);
								StockBean stock=new StockBean();
								stock.setStock(0);
								stock.setStockMinimo(stockMin);
								RodamientoBean rod=new RodamientoBean();
								rod.setCodigo(String.valueOf(codigo));
								rod.setMarca(txtMarca.getText());
								rod.setNombre(txtNombre.getText());
								rod.setOrigen(txtOrigen.getText());
								rod.setPrecio(precio);
								rod.setStock(stock);
								//Guadar Rodamiento
								Exito e=new Exito();
								e.setLocationRelativeTo(null);
								e.setVisible(true);
								this.limpiarText();
							}
						}catch(Exception e){
							
							
						}
						
						
					}

					private void limpiarText() {
						txtCodigo.setText("");
						txtMarca.setText("");
						txtNombre.setText("");
						txtOrigen.setText("");
						txtPrecio.setText("");
						txtStockMinimo.setText("");
					}
				});
			}
			{
				jButtonCancelar = new JButton();
				getContentPane().add(jButtonCancelar);
				jButtonCancelar.setText("CANCELAR");
				jButtonCancelar.setBounds(199, 208, 98, 34);
				jButtonCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
					}
				});
			}
			pack();
			this.setSize(400, 302);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
